package com.abbas.abchat.db;

import android.content.Context;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.abbas.abchat.entity.FriendRound;

/**
 * @author abbas
 * @description: Database
 * @date 2022/4/12 20:14
 */
public class Sqlite extends SQLiteOpenHelper {

    /**
     * database name
     */
    public static String DB_NAME = "AbChatDb";

    public Sqlite(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    public Sqlite(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version, @Nullable DatabaseErrorHandler errorHandler) {
        super(context, name, factory, version, errorHandler);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        //E/SQLiteLog: (1) AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY
        db.execSQL("create table account(_id INTEGER not null primary key autoincrement,account VARCHAR(40) unique,password VARCHAR(40),name VARCHAR(40),balance Double,chatTableDbName VARCHAR(40),imgPath Text)");
        db.execSQL("create table "+ FriendRound.DB_Name+"("+FriendRound.ID+" INTEGER not null primary key autoincrement,"+FriendRound.PUB_DATE+" VARCHAR(40),"+FriendRound.P_ID+" INTEGER,"+FriendRound.LOCATION+" VARCHAT(40),"+FriendRound.CONTENT+" Text)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
